package algorithm;

/**
 * Created by kevin on 15-1-4.
 */
public class Complex {
    private  double re,im;

    public Complex(double real,double imag){
        re = real;
        im = imag;
    }

    public double re(){
        return re;
    }

    public double im(){
        return im;
    }

    public String toString(){
        return re() + " + " + im() + "i";
    }

    public Complex plus(Complex b){
        double real = re + b.re;
        double image = im + b.im;
        return new Complex(real,image);
    }

    public Complex times(Complex b){
        double real = re * b.re - im * b.im;
        double imag = re * b.im + im * b.re;
        return new Complex(real,imag);
    }

    public double abs(){
        return Math.sqrt(re * re + im * im);
    }
}
